﻿using Entity;
using Microsoft.AspNetCore.Http;
using ServiceCore;
using ServiceCore.Tool.MiniProgram;
using ServiceCore.Tool.Mqtt;
using ServiceCore.Tool.NPOI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;

namespace Customer.Bussiness_Service
{
    public interface Irk_mini_service
    {
        /// <summary>
        /// 登录凭证校验。通过 wx.login 接口获得临时登录凭证 code 后传到开发者服务器调用此接口完成登录流程。
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        ResultObjModel code2Session(string code);
        /// <summary>
        /// 用户支付完成后，获取该用户的 UnionId
        /// </summary>
        /// <param name="openid"></param>
        /// <returns></returns>
        ResultObjModel getPaidUnionId(string openid);
    }
    public class rk_mini_service: Irk_mini_service
    {

        private readonly IMiniProgramApi _mini_service;
        public rk_mini_service(IMiniProgramApi Mini_service)
        {
            _mini_service = Mini_service;
        }
        /// <summary>
        /// 登录凭证校验。通过 wx.login 接口获得临时登录凭证 code 后传到开发者服务器调用此接口完成登录流程。
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public ResultObjModel code2Session(string code)
        {
            return CoreStartDo.ResultAction(result =>
            {
                result.code = 0;
                result.msg = "success";
                result.data = _mini_service.code2Session(code);
                return result;
            });
        }
         
        /// <summary>
        /// 用户支付完成后，获取该用户的 UnionId
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public ResultObjModel getPaidUnionId(string openid)
        {
            return CoreStartDo.ResultAction(result =>
            {
                result.code = 0;
                result.msg = "success";
                result.data = _mini_service.getPaidUnionId(openid);
                return result;
            });
        }
    }
}
